<template>
    <div class="musciListDetail">
        <!-- 歌曲信息 -->
        <div class="listInfo" v-if="isShow">
            <div class="listImg">
                <img :src="musicListDetail.coverImgUrl">
            </div>
            <div class="right">
                <div class="title">
                    <div class="titleTag">歌单</div>
                    <div class="titleContent">{{ musicListDetail.name }}</div>
                </div>
                <div class="user">
                    <div class="userAvatar">
                        <img :src="musicListDetail.creator.avatarUrl">
                    </div>
                    <div class="userName">{{musicListDetail.creator.nickname}}</div>
                    <div class="creatTime">{{creatTime}}创建</div>
                </div>
                <div class="buttons">
                    <div class="playAll buttonItem"><i class="iconfont icon-play"></i><span>播放全部</span></div>
                    <div class="buttonItem"><i class="iconfont icon-aixin"></i><span>收藏</span></div>
                    <div class="buttonItem"><i class="iconfont icon-share"><span>分享</span></i></div>
                </div>
                <div class="tags">
                    标签：<div class="tagItem" v-for="(item, index) in musicListDetail.tags" :key="index">
                        {{ item }}
                    </div>
                </div>
                <div class="otherInfo">
                    <div class="muicnNum">歌曲：{{ musicListDetail.trackCount }}</div>
                    <div class="playCount">播放：{{ musicListDetail.playCount}}</div>
                </div>
                <div class="desc">
                    简介:{{
                    musicListDetail.description
                    ? musicListDetail.description
                    : "暂无简介"
                    }}
                </div>
            </div>
        </div>
        <!-- Tabs -->
        <div class="musicList">
            <el-tabs class="demo-tabs" v-model="activeName">
                <el-tab-pane label="歌曲列表" name="first">
                    <el-table :data=musicListDetail.tracks size="mini" style="width: 100%" @row-dblclick="clickRow" highlight-current-row stripe>
                        <el-table-column label="" width="60" type="index">
                        </el-table-column>
                        <el-table-column label="" width="80">
                            <!-- 下载按钮 -->
                            <i class="iconfont icon-download"></i>
                        </el-table-column>
                        <el-table-column prop="name" label="音乐标题" min-width="350">
                        </el-table-column>
                        <el-table-column prop="ar[0].name" label="歌手" min-width="120">
                        </el-table-column>
                        <el-table-column prop="al.name" label="专辑" min-width="170">
                        </el-table-column>
                        <el-table-column prop="dt" label="时长" min-width="100">
                        </el-table-column>
                    </el-table>
                </el-tab-pane>
                <el-tab-pane label="评论" name="second">Config</el-tab-pane>
                <el-tab-pane label="收藏者" name="third">Role</el-tab-pane>
            </el-tabs>
        </div>
    </div>
</template>

<script setup>
import { ref, computed, onBeforeMount } from 'vue'
import { useRoute } from 'vue-router';
import request from '../../api';
import dayjs from 'dayjs'
import useStore from '../../store/idnex'
import { handleMusicTime } from '../../utils/utils'
onBeforeMount(() => {
    getMusicListDetail()
})
const store = useStore()

const route = useRoute()
// 由于拿到数据之前渲染dom会报错，所以在获得数据之前先用v-if来控制dom的显示
const isShow = ref(false)
// 歌单详情数据
let musicListDetail = ref({})
//默认激活的面板
const activeName = ref('first')
const getMusicListDetail = async () => {
    let res = await request('/playlist/detail',{id:route.params.id})
    if (res.data.code === 200) {
        musicListDetail.value =  res.data.playlist
        isShow.value = true
        musicListDetail.value.tracks.forEach(item => {
            item.dt = handleMusicTime(null,item.dt)
        })
    }
}

let creatTime = computed(()=> {
    return dayjs(musicListDetail.value.createTime).format('YYYY-MM-DD');
})

const clickRow = async (row) => {
    // console.log(row);
    //将musicId提交到vuex中，供bottomControl查询歌曲url
    store.updateMusicId(row.id)
    // 如果歌单发生变化，提交歌单到store
    if (musicListDetail.value.id != store.musicListId) {
        store.updateMuiscList({
            musicList:musicListDetail.value.tracks,
            musicListId:musicListDetail.value.id
        })
    }
    
}

</script>

<style lang="scss" scoped>
.musciListDetail{
    overflow-y: scroll;
    overflow-x: hidden;
}
.listInfo {
    display: flex;
}

.listImg {
    height: 175px;
    width: 175px;
    border-radius: 10px;
    overflow: hidden;
    margin-right: 15px;

    img {
        width: 100%;

    }
}

.right {
    width: calc(100% - 200px);
}

.title {
    display: flex;
    align-items: center;

    .titleTag {
        font-size: 12px;
        color: #ec4141;
        border: 1px solid #ec4141;
        padding: 1px 2px;
        border-radius: 2px;
        margin-right: 5px;
        //缩放0.8
        transform: scale(0.8);
    }

    .titleContent {
        font-size: 25px;
        font-weight: 600;
        color: #373737;
        text-overflow: ellipsis;
        white-space: nowrap;

    }
}

.user {
    display: flex;
    margin-top: 8px;
    color: #666;

    .userAvatar {
        width: 25px;
        height: 25px;
        overflow: hidden;
        margin-right: 8px;


        img {
            width: 100%;
            border-radius: 50%;
        }
    }

    .userName {
        color: #6191c2;
        margin-right: 8px;
        cursor: pointer;
    }

    .creatTime {
        font-size: 15px;
        transform: scale(0.9);
    }
}

.buttons {


    display: flex;
    margin-top: 8px;

    div:hover {
        filter: brightness(0.97);
    }

    .buttonItem {
        font-size: 15px;
        border: 1px solid #ddd;
        border-radius: 20px;
        padding: 5px 15px;
        margin-right: 8px;
        cursor: pointer;
    }

    .playAll {
        background-color: #ec4141;
        color: white;


    }
}

.tags {
    font-size: 13px;
    margin-top: 8px;
    display: flex;
    color: #666;

    .tagItem {
        color: #6191c2;
        margin-right: 5px;
    }
}

.otherInfo {
    display: flex;
    font-size: 13px;
    margin-right: 15px;
    color: #666;
    margin-top: 5px;

    .muicnNum {
        margin-right: 15px;
    }
}

.desc {
    margin-top: 5px;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.musicList{
    margin-top: 10px;
    cursor: pointer;
    overflow-x: hidden;
}
</style>